// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 

package com.nnee.p_j;

  
import android.net.Uri;
import com.nnee.p_a.p_a.cls_e;
import com.nnee.p_a.p_a.cls_g;
import com.nnee.p_fk.p_a.cls_h;
import com.nnee.p_fk.p_a.cls_j;
import com.nnee.p_fk.p_a.cls_m;
import com.nnee.p_g.cls_b;
import com.nnee.p_i.cls_a;
import com.nnee.p_pr.p_a.cls_t;
import com.nnee.p_pr.p_a.cls_u;
import com.nnee.p_pr.p_d.cls_c;
import com.nnee.p_pr.p_prot.cls_l;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URI;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.zip.GZIPInputStream;
import junit.framework.Assert;
import org.apache.http.Header;
import org.apache.http.HttpResponse;
import org.apache.http.client.CookieStore;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpHead;
import org.apache.http.client.methods.HttpOptions;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpParams;
import org.apache.http.params.HttpProtocolParams;

// Referenced classes of package com.nnee.j:
//            f

public class cls_d
    implements cls_f
{

    public cls_d(HttpClient httpclient)
    {
        e = null;
        f = new cls_j();
        h = -1;
        c = httpclient;
    }

    public static cls_f a(HttpClient httpclient, cls_m m1)
    {
        cls_d d1 = new cls_d(httpclient);
        d1.a(m1);
        return d1;
    }

    private HttpResponse a(HttpRequestBase httprequestbase) throws Exception
    {
        if(httprequestbase == null)
            throw new Exception();
        if(i)
            throw new IOException("Http closed");
        HttpResponse httpresponse2 = c.execute(httprequestbase);
        HttpResponse httpresponse1;
        httpresponse1 = httpresponse2;
        if(i)
        {
            l();
            throw new IOException("close after execute");
        }
//        break MISSING_BLOCK_LABEL_141;
//        NullPointerException nullpointerexception;
//        nullpointerexception;
        
         
        HttpResponse httpresponse;
        if(i)
        {
            l();
            throw new IOException("close after execute");
        } 
        httpresponse = c.execute(httprequestbase);
        httpresponse1 = httpresponse;
        if(i)
        {
            l();
            throw new IOException("close after execute");
        }
        return httpresponse1;
    }

    private void a(InputStream inputstream, OutputStream outputstream, int i1) throws IOException
    {
        byte abyte0[] = new byte[4096];
        int j1 = 0;
        int k1 = 0;
        do
        {
            if(k1 >= i1 || i)
                break;
            int l1 = inputstream.read(abyte0, j1, Math.min(abyte0.length - j1, i1 - k1));
            if(l1 == -1)
                throw new IOException("http readData from stream num mismatch");
            j1 += l1;
            k1 += l1;
            if(j1 == 4096)
            {
                outputstream.write(abyte0, 0, 4096);
                j1 = 0;
            }
        } while(true);
        if(j1 > 0)
            outputstream.write(abyte0, 0, j1);
        if(i)
            throw new IOException("http readData from stream close flg is set");
        else
            return;
    }

    private boolean a(HttpResponse httpresponse)
    {
    	boolean flag;
        if(httpresponse == null || !b.d()) {
        	flag = false;
        } else {
        	Header header = httpresponse.getFirstHeader("Set-Cookie");
            if(header == null) {
            	flag = false;
            } else {
            	Uri uri = Uri.parse(b.b());
                a.put(uri.getHost(), header.getValue());
                flag = true;
            }
        }

        return flag;

    }

    public static void j()
    {
        if(a != null)
            a.clear();
    }

    private void l()
    {
    }

    private int m()
    {
    	int k1 =0;
        int i1=0;
        if(e != null)
        {
            e.abort();
            e = null;
        }
        i1 = -1;
        switch(f.a())
        {
      
        case 1:
        	 e = b(b);
             try {
				f.a(a(e));
			} catch (Exception e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
             int j1 = f.e();
             if(j1 == 304)
             {
                 if(b.z())
                     com.nnee.p_a.p_a.cls_e.a(b, f, null, 0, false, this);
                 f.a((String)null);
                 k1 = j1;
             } else
             if(j1 == 200)
             {
                 if(b.z() && b.B())
					try {
						com.nnee.p_a.p_a.cls_e.a(b, f, o(), (int)i(), true, this);
					} catch (IOException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
                 f.a((String)null);
                 k1 = j1;
             } else
             if(j1 != 401)
             {
                 f.a((String)null);
                 k1 = j1;
             } else
             {
                 k1 = j1;
             }
               
        	break;
        case 2:
        	 e = b(b);
             try {
				f.a(a(e));
			} catch (Exception e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
             i1 = f.e();
             if(i1 != 200)
                 return k1;
             if(!b.z() || !b.B()) {
            	 k1 = i1;
             } else{
            	 cls_g g1=null;
				try {
					g1 = com.nnee.p_a.p_a.cls_e.a(b, f.d(), o(), (int)i(), this);
				} catch (IOException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
                 if(!b.x())
                     com.nnee.p_a.p_a.cls_e.a(b.v(), g1);
                 else
                 if(g1 != null)
                     f.a(g1.e());
                 k1 = i1;
                   
                 if(i1 == 401) {
                	 k1 = i1;
                 } else {
                	 f.a((String)null);
                     k1 = i1;
                 }
             }
        	break;
        default:
        	k1 = i1;
        	break;
        }
        
        if(k1 == 401 && b.d())
        {
            CookieStore cookiestore = ((DefaultHttpClient)c).getCookieStore();
            if(cookiestore != null)
                cookiestore.clear();
        }
        HttpResponse httpresponse = f.d();
        a(httpresponse);
        if(k1 == 401)
        {
            cls_h h1 = b.a(httpresponse);
            if(b.d() && h1 != null)
                b.b(h1.a(), h1.b());
            if(e != null)
            {
                e.abort();
                e = null;
            }
        }
        return k1;
       
    }

    private InputStream n()
    {
        if(d == null)
            d = f.g();
        return d;
    }

    private InputStream o() throws IOException
    {
        InputStream inputstream = n();
        if(inputstream == null || i)
            throw new IOException("closed");
        cls_a a1 = new cls_a(inputstream);
        if(f.d() != null)
            a1.a(b.D());
        return a1;
    }

    private byte[] p() throws IOException
    {
    	long l1;
        int k1;
        long l2;
        
        int i1;
        byte abyte0[];
        int j1;
        byte abyte1[];
        byte abyte2[];
        Exception exception2;
        byte abyte3[];
        Exception exception3;
        
    	ByteArrayOutputStream bytearrayoutputstream;
    	cls_a a2;
        InputStream inputstream;
        inputstream = n();
        if(inputstream == null || i)
            throw new IOException("closed");
        a2 = new cls_a(inputstream);
        if(f.d() != null)
            a2.a(b.D());
        bytearrayoutputstream = new ByteArrayOutputStream();
        i1 = (int)f.f();
        if(i1 <= 0)
            return null;
        a(a2, bytearrayoutputstream, i1);
        abyte3 = bytearrayoutputstream.toByteArray();
        abyte2 = abyte3;
        if(a2 != null)
            try
            {
                a2.close();
            }
            // Misplaced declaration of an exception variable
            catch(Exception exception31) { }
        return abyte2;
//        Exception exception;
//        exception;
//        cls_a a1 = null;
//_L6:
//        
//        
//        if(a1 != null)
//            try
//            {
//                a1.close();
//            }
//            catch(Exception exception1) { }
//        throw exception;
//_L1:
//        a2 = new cls_a(inputstream);
//        if(f.d() != null)
//            a2.a(b.D());
//        bytearrayoutputstream = new ByteArrayOutputStream();
//        i1 = (int)f.f();
//        if(i1 <= 0)
//            break MISSING_BLOCK_LABEL_132;
//        a(a2, bytearrayoutputstream, i1);
//        abyte3 = bytearrayoutputstream.toByteArray();
//        abyte2 = abyte3;
//        if(a2 != null)
//            try
//            {
//                a2.close();
//            }
//            // Misplaced declaration of an exception variable
//            catch(Exception exception3) { }
//        return abyte2;
//        l1 = System.currentTimeMillis();
//        abyte0 = new byte[4096];
//        j1 = 0;
//_L9:
//        if(i) goto _L3; else goto _L2
//_L2:
//        k1 = a2.read(abyte0, j1, abyte0.length - j1);
//        l2 = System.currentTimeMillis();
//        if(k1 >= 0) goto _L4; else goto _L3
//_L8:
//        j1 += k1;
//        if(j1 == 4096)
//        {
//            bytearrayoutputstream.write(abyte0, 0, 4096);
//            j1 = 0;
//        }
//          goto _L5
//_L3:
//        if(j1 > 0)
//            bytearrayoutputstream.write(abyte0, 0, j1);
//        if(i)
//            throw new IOException("Http readData close flg is set");
//        abyte1 = bytearrayoutputstream.toByteArray();
//        abyte2 = abyte1;
//        if(a2 != null)
//            try
//            {
//                a2.close();
//            }
//            // Misplaced declaration of an exception variable
//            catch(Exception exception2) { }
//        break MISSING_BLOCK_LABEL_129;
//        exception;
//        a1 = a2;
//          goto _L6
//_L4:
//        if(k1 != 0) goto _L8; else goto _L7
//_L7:
//        if(l2 - l1 <= 5000L) goto _L9; else goto _L3
//_L5:
//        l1 = l2;
//          goto _L9
    }

    public void a(int i1)
    {
        h = i1;
    }

    public void a(cls_m m1)
    {
        b = m1;
        m1.a();
        if(m1.w())
            if(m1.x())
            {
                f.a(com.nnee.p_a.p_a.cls_e.a(m1.v(), m1.A()));
            } else
            {
                cls_g g1 = com.nnee.p_a.p_a.cls_e.a(m1.t(), m1.v(), m1.A());
                f.a(g1);
            }
    }

    public boolean a()
    {
        return i;
    }

    public int b() throws Exception
    {
    	int k = 200;
        try
        {
          if (!cls_u.e(com.nnee.p_b.p_a.cls_d.h().a()))
          {
            if ((this.f.c() != null) || (this.f.b() != null))
            {
              boolean bool = com.nnee.p_pr.p_c.cls_h.b(com.nnee.p_b.p_a.cls_d.h().a(), com.nnee.p_b.p_a.cls_d.h().c(), com.nnee.p_b.p_a.cls_d.h().d());
              if (bool)
              {
                if (!this.i)
                  return k;
                e();
                throw new IOException("http execute closed");
              }
            }
            throw new com.nnee.p_fk.p_a.cls_e();
          }
        }
        catch (Exception localException)
        {
          localException.printStackTrace();
          throw localException;
        }
        finally
        {
          if (this.i)
          {
            e();
//            throw new IOException("http execute closed");
            if ((0x2 & this.b.h()) != 0)
            {
              com.nnee.p_l.p_c.cls_a locala = com.nnee.p_b.p_a.cls_d.h().b();
              if ((locala == null) || (!locala.a("system_setting_offline", false)))
              {
            	  cls_t localt = cls_u.c(com.nnee.p_b.p_a.cls_d.h().a());
                if ((localt == cls_t.dEWirelessNET) || (localt == cls_t.cEWirelessWAP))
                  throw new com.nnee.p_e.cls_a();
              }
            }
            if (com.nnee.p_pr.p_app.cls_e.a)
              com.nnee.p_g.cls_b.e("Http", "execute url is:" + this.b.b());
            int n = m();
            if ((n == 401) && (this.b.d()))
            {
              n = m();
              if (n == k)
              {
                com.nnee.p_b.p_a.cls_d.h().a(com.nnee.p_h.cls_b.dELogin);
                com.nnee.p_pr.p_d.cls_c.a(0L, com.nnee.p_b.p_a.cls_d.h().c());
              }
            }
            int i1 = n;
            if (i1 == 401)
              this.f.a((String )null);
            while (true)
              if (this.f != null)
              {
                int i2 = this.f.e();
                k = i2;
                if (!this.i)
                  break;
                e();
//                throw new IOException("http execute closed");
                if (i1 != 403)
                  continue;
                Header localHeader = this.f.d().getFirstHeader("X-Error");
                if (localHeader == null)
                  continue;
                com.nnee.p_g.cls_b.d("403 X-Error", "" + localHeader.getValue());
                continue;
              }
              else
              {
                k = -1;
                if (!this.i)
                  break;
                e();
                throw new IOException("http execute closed");
              }
          }
        }
        label443: return k;
    }

    HttpRequestBase b(cls_m m1)
    {
        Object obj;
        URI uri;
        List list;
        if(m1.o() == com.nnee.p_fk.p_a.cls_b.aGET)
            obj = new HttpGet();
        else
        if(m1.o() == com.nnee.p_fk.p_a.cls_b.eHEAD)
            obj = new HttpHead();
        else
        if(m1.o() == com.nnee.p_fk.p_a.cls_b.bPOST)
        {
            HttpPost httppost = new HttpPost();
            org.apache.http.HttpEntity httpentity = m1.p();
            if(httpentity != null)
                httppost.setEntity(httpentity);
            obj = httppost;
        } else
        if(m1.o() == com.nnee.p_fk.p_a.cls_b.cPUT)
        {
            HttpPut httpput = new HttpPut();
            org.apache.http.HttpEntity httpentity1 = m1.p();
            if(httpentity1 != null)
                httpput.setEntity(httpentity1);
            obj = httpput;
        } else
        if(m1.o() == com.nnee.p_fk.p_a.cls_b.fOPTIONS)
            obj = new HttpOptions();
        else
        if(m1.o() == com.nnee.p_fk.p_a.cls_b.dDELETE)
        {
            obj = new HttpDelete();
        } else
        {
            Assert.assertTrue(false);
            obj = null;
        }
        uri = URI.create(m1.b());
        ((HttpRequestBase) (obj)).setURI(uri);
        ((HttpRequestBase) (obj)).setParams(c(m1));
        list = m1.s();
        if(list != null)
        {
            cls_h h1;
            for(Iterator iterator = list.iterator(); iterator.hasNext(); ((HttpRequestBase) (obj)).addHeader(h1.a(), h1.b()))
                h1 = (cls_h)iterator.next();

        }
        if(m1.d())
        {
            String s = uri.getHost();
            String s1 = (String)a.get(s);
            if(s1 != null)
                ((HttpRequestBase) (obj)).addHeader("Cookie", s1);
        }
        if(f.a() == 1 && f.h() != null)
            ((HttpRequestBase) (obj)).addHeader("If-Modified-Since", f.h());
        return ((HttpRequestBase) (obj));
    }

    HttpParams c(cls_m m1)
    {
        BasicHttpParams basichttpparams = new BasicHttpParams();
        HttpProtocolParams.setVersion(basichttpparams, cls_l.c);
        return basichttpparams;
    }

    public void c()
    {
        if(i || g == null || f.d() == null || !b.z() || b.B())
        	return;
        if(f.b() != null)
        {
            if(f.e() == 200)
                com.nnee.p_a.p_a.cls_e.a(b, f, new ByteArrayInputStream(g), g.length, true, this);
            return;
        }
        cls_g g1 = com.nnee.p_a.p_a.cls_e.a(b, f.d(), new ByteArrayInputStream(g), g.length, this);
        com.nnee.p_a.p_a.cls_d d1;
        if(!b.x())
        {
            com.nnee.p_a.p_a.cls_e.a(b.v(), g1);
            return;
        }
        if(g1 != null)
			f.a(g1.e());
    }

    public int d()
    {
        int i1;
        if(f != null)
            i1 = f.e();
        else
            i1 = -1;
        return i1;
    }

    public void e()
    {
        i = true;
        if(e != null)
        {
            e.abort();
            e = null;
        }
        if(d != null)
            try
            {
                d.close();
                d = null;
            }
            catch(Exception exception)
            {
                exception.printStackTrace();
            }
        l();
        g = null;
        if(f != null)
        {
            f.a((String)null);
            f.a((String)null);
        }
    }

    public byte[] f()
    {
        if(g == null)
			try {
				g = p();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
        return g;
    }

    public String g()
    {
        String s;
        if(f != null)
        {
            if(b.y() && f.c() != null)
                s = "gzip";
            else
                s = f.i();
        } else
        {
            s = null;
        }
        return s;
    }

    public String h()
    {
        String s;
        if(f != null)
            s = f.j();
        else
            s = null;
        return s;
    }

    public long i()
    {
        long l1;
        if(f != null)
            l1 = f.f();
        else
            l1 = -1L;
        return l1;
    }

    public Object k()
    {
        String s = g();
        Object obj=null;
        if(s != null && "gzip".equals(s))
        {
            byte abyte0[] = f();
            if(abyte0 != null)
				try {
					obj = new GZIPInputStream(new cls_a(new ByteArrayInputStream(abyte0)));
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			else
                obj = null;
        } else
        {
            obj = f();
        }
        return obj;
    }

    static HashMap a = new HashMap();
    static int j = 0;
    private static final String l = "Http";
    private static final int m = 4096;
    cls_m b;
    HttpClient c;
    InputStream d;
    HttpRequestBase e;
    cls_j f;
    byte g[];
    int h;
    boolean i;

    static 
    {
        j = 8192;
    }
}
